<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head>
	<th:block th:include="include :: header('泵站详情')" />
</head>
<body>
    <div class="container-div">
    <input name="stationId" autocomplete="off" id="psId"  class="form-control" type="hidden" th:value="${pumpStationInfo.id}" >
    	<div class="row">
    		 <div th:include="biz/pumpStation/include::detail-header"></div> 
    		<div class="col-sm-12" style="margin-top: 15px;">
		    	<div class="btn-group-sm" id="toolbar" role="group">
					 <a class="btn btn-success" onclick="addRela()" shiro:hasPermission="biz:sur:add">
						<i class="fa fa-plus"></i> 添加管理者
					</a> 
				</div>
				<table id="rela-table" data-mobile-responsive="true"></table>
    		</div>
    	</div>
	</div>
    <div th:include="include::footer"></div>
    <script th:inline="javascript">
    	var prefix = ctx + "biz/stationUserRelation";
    	var editFlag = [[${@permission.hasPermi('biz:suredit')}]];
        var removeFlag = [[${@permission.hasPermi('biz:sur:remove')}]];
        var types = [[${@dict.getType('biz_is_valid')}]];
        var datas = [[${@dict.getType('biz_is_delete')}]];
        var prefix = ctx + "biz/stationUserRelation";
        
        function addRela(){
        	/* var url = prefix + '/add?stationId='+[[${pumpStationInfo.id}]]+'&stationName=' + [[${pumpStationInfo.name}]];
        	$.modal.open('添加管理者', url); */
        	//var url = ctx + "system/user/add";
        	var url = ctx + 'biz/stationUserRelation/addUser?stationId='+[[${pumpStationInfo.id}]]+'&stationName=' + [[${pumpStationInfo.name}]];
        	$.modal.open('添加管理者', url);
        }
        
        
        $(function() {
        	var stationId = [[${pumpStationInfo.id}]];
            var options = {
            	id: "rela-table",
                url: prefix + "/set/list?stationId="+[[${pumpStationInfo.id}]],
                //createUrl: prefix + "/add",
                removeUrl: prefix + "/remove",
                modalName: "泵站与用户关系管理",
                columns: [
				{
					field : 'userName', 
					title : '管理者名称' 
				},
				{
					field : 'phoneNumber', 
					title : '管理者手机' 
				},
				{
					field : 'stationName', 
					title : '泵站名称' 
				},
				{
					field : 'address', 
					title : '泵站地址' 
				},
				
				/* {
		            field: 'isValid',
		            title: '是否有效',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	return statusTools(row);
		            }
		        }, */
				{
					field : 'createBy', 
					title : '创建者' 
				},
				{
		            field: 'createTime',
		            title: '创建时间',
		            sortable: false
		        },
		        {
		            field: 'remark',
		            title: '备注'
		        },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	//actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="toEditUser(\'' + row.userId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
		            	if( row.stationId == stationId  ){
		            		actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>解绑</a>');
		            	}else{
		            		actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="bindToManage(\'' + row.userId +'\''+','+'\''+stationId+ '\')"><i class="fa fa-plus"></i>绑定</a> ');
		            	}
                        
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });
        
        
        function toEditUser(userId){
        	var url = ctx + "system/user/edit/"+userId;
        	$.modal.open('编辑', url);
        }
        
        function bindToManage(userId,stationId){
        	$.modal.confirm("确认要绑定吗？", function() {
				$.operate.post(prefix + "/saveBindInfo", { "userId": userId, "stationId": stationId });
		    })
        }
        
		function statusTools(row) {
		    if (row.isValid == 0) {
    			return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
    		} else {
    			return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
    		}
		}
		
		function disable(id) {
			$.modal.confirm("确认要失效吗？", function() {
				$.operate.post(prefix + "/changeStatus", { "id": id, "status": 0 });
		    })
		}

		function enable(id) {
			$.modal.confirm("确认要启用吗？", function() {
				$.operate.post(prefix + "/changeStatus", { "id": id, "status": 1 });
		    })
		}
         
      
    </script>
</body>
</html>
